# ------------------------------------------------------------------------------
# Makes all targets for 08_train_split_model directory
# Author: Cassidy Shubatt <cshubatt@gmail.com>
# To run: bsub -q big -R "rusage[mem=150000]" make
# ------------------------------------------------------------------------------

# Config -----------------------------------------------------------------------
.ONESHELL:
include config.mk

# Recipes ----------------------------------------------------------------------
## all			: Makes split model performance comparison figure
.PHONY: all

## splits		: Splits cohort into two subcohorts, on which to identically train separate models
.PHONY: splits
splits: $(SPLITS)
$(SPLITS): 01_prep_split.sh \
scripts/01_prep_split.R $(DIRS)
	bash $<

## lassos		: Trains lassos on 2 subcohorts
.PHONY: lassos
lassos: $(LASSOS)
$(LASSOS): 02_fit_lassos.sh \
scripts/02_fit_lassos.R $(SPLITS)
	bash $<

## tune_gbms		: Tunes GBMS on 2 subcohorts
.PHONY: tune_gbms
tune_gbms: $(TUNE_GBMS)
$(TUNE_GBMS): 03_tune_gbms.sh \
scripts/03_tune_gbms.R $(SPLITS)
	bash $<

## gbms		: Fits GBMS on 2 subcohorts
.PHONY: gbms
gbms: $(GBMS)
$(GBMS): 04_fit_gbms.sh \
scripts/04_fit_gbms.R $(TUNE_GBMS)
	bash $<

## subscores	: Predicts subscores for all GBMs, LASSOs.
.PHONY : subscores
subscores : $(SUBSCORES)
temp/subscores_%_set.rds : 05_predict_subscores.sh \
scripts/05_predict_subscores.R $(LASSOS) $(GBMS)
	bash $< $*

## ensembles		: Fits ensembles on 2 subcohorts
.PHONY: ensembles
ensembles: $(ENSEMBLES)
$(ENSEMBLES): 06_fit_ensemble.sh \
scripts/06_fit_ensemble.R $(SUBSCORES)
	bash $<

## scores		: Gets test-set scores from identically-trained models
.PHONY: scores
scores: $(SCORES)
$(SCORES): 07_predict_test.sh \
scripts/07_predict_test.R $(ENSEMBLES)
	bash $<

## cdf_plot		: Plots comparative performance of two models
.PHONY: cdf_plot
cdf_plot: $(CDF_PLOT)
$(CDF_PLOT): 08_plot_outcomes.sh \
scripts/08_plot_outcomes.R $(SCORES)
	bash $<

# Helper Recipes ---------------------------------------------------------------
.PHONY: dirs
dirs: $(DIRS)
%/.f :
	mkdir -p $(dir $@)
	touch $@

.PHONY: clean
clean:
	rm -rf temp log

## style			: Styles R scripts according to tidyverse guidelines
.PHONY: style
style:
	source ~/anaconda3/etc/profile.d/conda.sh
	conda activate stressr
	R --vanilla --silent -e "styler::style_dir(path = 'scripts', filetype = c('R', 'Rmd', 'Rprofile'))"

## help			: Prints available .PHONY targets with description
.PHONY : help
help : Makefile
	@sed -n 's/^##//p' $<
